﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Grabacr07.KanColleWrapper;
using Grabacr07.KanColleWrapper.Models;
using System.Web.Script.Serialization;

namespace FleetCode
{
    /// <summary>
    /// MainPanel.xaml 的交互逻辑
    /// </summary>
    public partial class MainPanel : UserControl
    {
        public MainPanel()
        {
            InitializeComponent();
        }

        private void btnGo_Click(object sender, RoutedEventArgs e)
        {
            JavaScriptSerializer se = new JavaScriptSerializer();
            se.RegisterConverters(new JavaScriptConverter[] { new NullPropertiesConverter() });

            string text = se.Serialize(Model.Root.Convert(KanColleClient.Current.Homeport.Organization.Fleets.Values));
            txtData.Text = text;
            if (chkClip.IsChecked ?? false)
            {
                try { Clipboard.SetText(text); }
                catch (System.Runtime.InteropServices.COMException)
                {
                    MessageBox.Show(
                        "无法操作剪贴板" + Environment.NewLine +
                        "请尝试手动复制" + Environment.NewLine +
                        "这可能与某些监视剪贴板的软件有关",
                        "总有刁民想害朕",
                        MessageBoxButton.OK,
                        MessageBoxImage.Exclamation);
                }
            }
        }
    }
}
